﻿using SD.Infrastructure.EntityBase;
using System;
using SlamDunk.ValueObjects.Enums;

namespace SlamDunk.MES.Domain.Entities.DefinitionContext
{
    /// <summary>
    /// 物料清单项
    /// </summary>
    public class BomItem : PlainEntity, ISortable
    {
        #region # 构造器

        #region 00.无参构造器
        /// <summary>
        /// 无参构造器
        /// </summary>
        protected BomItem() { }
        #endregion

        #region 01.创建物料清单项构造器
        /// <summary>
        /// 创建物料清单项构造器
        /// </summary>
        /// <param name="materialId">物料定义Id</param>
        /// <param name="directionType">物料输入/输出类型</param>
        /// <param name="quantity">数量</param>
        /// <param name="lossCoefficient">耗损系数</param>
        /// <param name="sort">排序</param>
        /// <param name="description">描述</param>
        public BomItem(Guid materialId, MaterialDirectionType directionType, decimal quantity, decimal lossCoefficient, int sort, string description)
            : this()
        {
            this.MaterialId = materialId;
            this.DirectionType = directionType;
            this.Quantity = quantity;
            this.LossCoefficient = lossCoefficient;
            this.Sort = sort;
            this.Description = description;
        }
        #endregion

        #endregion

        #region # 属性

        #region 物料定义Id —— Guid MaterialId
        /// <summary>
        /// 物料定义Id
        /// </summary>
        public Guid MaterialId { get; private set; }
        #endregion

        #region 物料输入/输出类型 —— MaterialDirectionType DirectionType
        /// <summary>
        /// 物料输入/输出类型
        /// </summary>
        public MaterialDirectionType DirectionType { get; private set; }
        #endregion

        #region 数量 —— decimal Quantity
        /// <summary>
        /// 数量
        /// </summary>
        public decimal Quantity { get; private set; }
        #endregion

        #region 耗损系数 —— decimal LossCoefficient
        /// <summary>
        /// 耗损系数
        /// </summary>
        public decimal LossCoefficient { get; private set; }
        #endregion

        #region 排序 —— int Sort
        /// <summary>
        /// 排序
        /// </summary>
        public int Sort { get; private set; }
        #endregion

        #region 描述 —— string Description
        /// <summary>
        /// 描述
        /// </summary>
        public string Description { get; private set; }
        #endregion

        #region 只读属性 - 物料占比 —— decimal Ratio
        /// <summary>
        /// 只读属性 - 物料占比
        /// </summary>
        public decimal Ratio
        {
            get
            {
                return this.Quantity / this.Bom.RunSize;
            }
        }
        #endregion

        #region 导航属性 - 物料清单 —— Bom Bom
        /// <summary>
        /// 导航属性 - 物料清单
        /// </summary>
        public virtual Bom Bom { get; internal set; }
        #endregion

        #endregion
    }
}
